﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Data;

namespace Common.UI.Converters
{
	public class NumberToObjectConverter : IValueConverter
	{
		public Object IfMore { get; set; }
		public Object IfLess { get; set; }
		public Object IfEqual { get; set; }

		public Int32 Border { get; set; }

		public object Convert(object value, Type targetType, object parameter, string language)
		{
			if (value == null)
				return IfEqual ?? IfLess;

			if (value is Int32)
				return Convert((Int32)value);
			else
				return Convert((Int32)Math.Round((Double)value));
		}

		private object Convert(Int32 num)
		{
			if (num == Border && IfEqual != null)
				return IfEqual;
			return num < Border ? IfLess : IfMore;
		}

		public object ConvertBack(object value, Type targetType, object parameter, string language)
		{
			throw new NotImplementedException();
		}
	}
}
